1. Field of the Invention
The present invention relates to a method for optimizing processing of a character string during execution of a program, a computer system and a computer program for the same.
2. Description of the Related Art
In the class libraries of many programming languages, classes for retaining character strings (hereinafter, referred to as character string classes) are prepared as standard classes. By utilizing the abundant class libraries prepared in the system, a programmer completes programming work with higher productivity. The classes prepared in the class libraries, however, are made for general purposes. Accordingly, a program with high execution efficiency is not always produced by use of the aforementioned classes.
In Java (trademark) language, for example, java.lang.String class (hereinafter, referred to as String class) is prepared as one of the character string classes. In String class, replaceFirst( ) method is prepared. The replaceFirst( ) method replaces a portion in a character string, which matches a specified regular expression, with a different character string. The regular expression specified in the replaceFirst( ) method does not always include a regular expression metacharacter. A regular expression not including a metacharacter “set” may be specified, for example. According to this specification, the character string “set” is thus replaced with a character string “get,” for example.
The aforementioned replacement can be also implemented by combining String.indexOf( ) method and String.substring( ) method, for example. When the replacement is implemented by the aforementioned combination, the execution speed of the program is faster than in the case where the replacement is implemented by the replaceFirst( ) method. Meanwhile, the productivity and the general-purpose properties of the program are lower than in the case where the replaceFirst( ) method is implemented.
When the priority is given to the execution speed of the program, a programmer may employ a method of writing codes by selectively using either one of the replaceFirst( ) method and the aforementioned combination depending on whether or not the regular expression includes a metacharacter, for example. However, in a case where whether the regular expression includes a metacharacter is not determined until execution of the program, it is not realistic for the programmer to prepare both the implementation using the replaceFirst( ) method and the implementation using the aforementioned combination, and to maintain both the implementations.
Programmers improve the productivity of programming work by utilizing the character string classes prepared in the system. However, since the character string classes are made for general purposes, a program with high execution efficiency is not always produced. In this respect, a technique for producing a program with high execution efficiency without lowering the productivity of the program is in demand.